package com.keyancompany.zhongbaopingtai.activity;

import android.support.v4.widget.SwipeRefreshLayout;

import com.alibaba.fastjson.JSONObject;
import com.keyancompany.zhongbaopingtai.Constants;
import com.keyancompany.zhongbaopingtai.api.FriendsAPI;
import com.keyancompany.zhongbaopingtai.model.BaseModel;
import com.keyancompany.zhongbaopingtai.model.MessageModel;

import java.util.List;

/**
 * Created by firefox on 2017/5/16.
 */

public abstract class BaseMessageActivity extends BaseActivity implements SwipeRefreshLayout.OnRefreshListener{

    protected int currentPage = 1 ;
    protected int total = 1;

    public void requestTask(int type , String fromUser){
        FriendsAPI.getLetterListByPid(type, fromUser,this,null);
    }

    /**
     * {"result":"sucess","token":"111111","data":{"total":1,"current":1,"list":[
     * {"createtime":创建时间,"message":消息内容,"FromUserName":发件人名称,"toUser":收件人,"fromUser":发件人pid,
     * "toUserName":收件人名称,"PID_":主键,"toHeadpic":收件人头像,"isread":是否已读（0未读，=1已读）,"isdelete":"",
     * "type":消息类型（0系统消息，1项目信息，2个人消息）,
     * shotType类型：（0:非操作1:好友2:团队邀请3:退出团队4:辞退5:专家6:选择调解人7:加入圈子）,
     * shotParameter:操作参数（用，分开）,"FromHeadpic":发件人头像}]},"msg":"查询成功！"}
     * @param type
     * @param json
     */
    @Override
    public void success(int type, String json) {
        super.success(type, json);
        refreshingFinish();
        BaseModel base = validateJson(json);
        if(base.isSuccess()){
            JSONObject object = JSONObject.parseObject(base.data);
            currentPage = object.getInteger(Constants.CURRENT);
            total = object.getInteger(Constants.TOTAL);
            List<MessageModel> list = JSONObject.parseArray(object.getString("list"), MessageModel.class);
            updateList(list);
        }
    }

    abstract void updateList( List<MessageModel> list);

    abstract void refreshingFinish();


}
